package com.stlm2.controller;

import com.stlm2.dems.service.IndexConfigService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by zlq on 2017/12/18.
 */
@Controller
@RequestMapping("indexConfigC")
public class indexConfigController {
    @Resource
    private IndexConfigService indexConfigService;

    @RequestMapping("indexConfig")
    public ModelAndView indexConfig(ModelAndView modelAndView){
        modelAndView.setViewName("/indexConfig/details");
        return modelAndView;
    }
    /*
*后台查询首页配置列表
* zlq
 */
    @ResponseBody
    @RequestMapping(value="/getlist.json",produces="application/json;charset=UTF-8")
    public  String  getList(ModelMap model ,String page,String typeValue,String token) {
        String data=null;
        try {
            data=indexConfigService.getList( model,page,typeValue,token);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

    @ResponseBody
    @RequestMapping(value="/modification.json",produces="application/json;charset=UTF-8")
    public  String  modification(ModelMap model,String token ,String id ,String name,String img ,String url,String memo,boolean state) {
        String data=null;
        try {
            data=indexConfigService.modification(model,token,id,name,img,url,memo,state);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"修改失败",data);
        }
        return  data;
    }


    @ResponseBody
    @RequestMapping(value="/getConfig.json",produces="application/json;charset=UTF-8")
    public  String  getConfig(ModelMap model) {
        String data=null;
        try {
            data=indexConfigService.getConfig( model,null);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }


    @ResponseBody
    @RequestMapping(value="/getDetails.json",produces="application/json;charset=UTF-8")
    public  String  getDetails(ModelMap model,String token,String id) {
        String data=null;
        try {
            data=indexConfigService.getDetails( model,token,id);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }
}
